from django.db import models

# Create your models here.
from utils.models import BaseModel
from goods.models import GoodsShelf
from user.models import UserInfo


class ShopCar(BaseModel):
    style = models.CharField(max_length=288, null=True, blank=True, verbose_name='商品款式')
    buy_num = models.IntegerField(verbose_name='购买数量', default=0)
    goods = models.ForeignKey(GoodsShelf, on_delete=models.CASCADE, db_constraint=False, verbose_name='商品')
    user = models.ForeignKey(UserInfo, on_delete=models.CASCADE, db_constraint=False, verbose_name='用户名')

    class Meta:
        db_table = 'shop_car'
        verbose_name = '购物车'
        verbose_name_plural = "购物车"

    def goods_info(self):
        return {'id': self.goods.id, 'detail': self.goods.goods_detail, 'name': self.goods.goods_name,
                'img': 'http://127.0.0.1:8000/media/' + str(self.goods.goods_img),
                'price': self.goods.selling_price, 'original_price': self.goods.original_price,
                'sales_num': self.goods.sales_num, 'stock_num': self.goods.stock_num}
